[id].vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <!-- 分类 -->
  3. <div class="main-background">
  4. <!-- SEO -->
  5. <Head>
  6. <Title>厦门市文化遗产保护中心 - {{ articlesData.content.value?.title }}</Title>
  7. <Meta name="description" content="" />
  8. <Meta name="keywords" content="" />
  9. </Head>
  10. <!-- 轮播 -->
  11. <Carousel v-bind="carouselConfig" class="main-header-image carousel-light">
  12. <Slide
  13. v-for="(item, key) in carouselData.content.value"
  14. :key="key"
  15. class="main-header-image"
  16. >
  17. <img class="main-header-image" v-if="item.image" :src="item.image" />
  18. </Slide>
  19. <template #addons>
  20. <Navigation />
  21. <Pagination />
  22. </template>
  23. </Carousel>
  24. <!-- 主要内容 -->
  25. <div class="main-content">
  26. <div class="container">
  27. <div class="row">
  28. <!-- 左侧导航 -->
  29. <div class="col-12 col-sm-12 col-md-4 col-lg-3">
  30. <div class="sidebar">
  31. <div class="title">
  32. <h2>{{ articlesData.content.value?.channel?.name }}</h2>
  33. </div>
  34. <ul class="sidebar-menu">
  35. <li @click="router.back()">
  36. <div>
  37. <Icon name="material-symbols:undo" />
  38. 返回上一级
  39. </div>
  40. </li>
  41. </ul>
  42. </div>
  43. </div>
  44. <!-- 右侧内容 -->
  45. <div class="col-12 col-sm-12 col-md-8 col-lg-9">
  46. <div class="content">
  47. <div class="section-title">
  48. <h2 class="icon">{{ articlesData.content.value?.channel?.name }}</h2>
  49. <nav aria-label="breadcrumb">
  50. <ol class="breadcrumb">
  51. <li class="breadcrumb-item"><a href="/">首页</a></li>
  52. <li class="breadcrumb-item active" aria-current="page">{{ articlesData.content.value?.channel?.name }}</li>
  53. </ol>
  54. </nav>
  55. </div>
  56. <SimplePageContentLoader :loader="articlesData">
  57. <div v-if="articlesData.content.value" class="news-detail">
  58. <h1>{{ articlesData.content.value.title }}</h1>
  59. <div class="times">
  60. <p class="date">时间:{{ DateUtils.formatDate(new Date(
  61. (articlesData.content.value.publishtime ||
  62. articlesData.content.value.createtime || 0) * 1000), 'yyyy-MM-dd') }}</p>
  63. <p class="views">浏览量: {{ articlesData.content.value.views }} </p>
  64. </div>
  65. <div v-if="!articlesData.content.value.content &&articlesData.content.value.image" class="head-image">
  66. <img :src="articlesData.content.value.image" />
  67. </div>
  68. <div class="content" v-html="articlesData.content.value.content">
  69. </div>
  70. <a-empty v-if="!articlesData.content.value.content"
  71. description="暂无内容"
  72. />
  73. </div>
  74. </SimplePageContentLoader>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script setup lang="ts">
  83. import { Carousel, Slide, Pagination, Navigation } from 'vue3-carousel'
  84. import { useSSrSimpleDataLoader } from '@/composeable/SimpleDataLoader';
  85. import { DateUtils } from '@imengyu/imengyu-utils';
  86. import SimplePageContentLoader from '~/components/content/SimplePageContentLoader.vue';
  87. const carouselConfig = {
  88. itemsToShow: 1,
  89. wrapAround: true,
  90. autoPlay: 5000,
  91. }
  92. const route = useRoute();
  93. const router = useRouter();
  94. const articleId = parseInt(route.params.id as string);
  95. const carouselData = await useSSrSimpleDataLoader('carousel', async () => {
  96. const res = await $fetch(`/api/carousel`);
  97. if (!res.status)
  98. throw new Error(res.message);
  99. return res.data;
  100. });
  101. const articlesData = await useSSrSimpleDataLoader('articles' + articleId, async () => {
  102. const res = await $fetch(`/api/article/${articleId}`, {
  103. method: 'GET',
  104. });
  105. if (!res.status)
  106. throw new Error(res.message);
  107. return res.data;
  108. });
  109. watch(() => route.query.id, async (newVal, oldVal) => {
  110. if (newVal !== oldVal) {
  111. articlesData.loadData(undefined, true);
  112. }
  113. });
  114. </script>
  115. <style lang="scss">
  116. @use "sass:list";
  117. @use "sass:math";
  118. </style>